using MicroMsg.Resource.@string;
using MicroMsg.UI.Page;
using Microsoft.Phone.Controls.Primitives;
using System;
using System.Diagnostics;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
namespace MicroMsg.UI.UserContrl
{
	public class MMToggleSwitch : UserControl
	{
		private const string ON_COLOR = "#5DB303";
		private const string OFF_COLOR = "#717171";
		public OnToggleStateChanged onToggleStateChanged;
		public static DependencyProperty TextProperty = DependencyProperty.Register("Text", typeof(string), typeof(MMToggleSwitch), new PropertyMetadata(null));
		public static DependencyProperty IsCheckedProperty = DependencyProperty.Register("IsChecked", typeof(bool), typeof(MMToggleSwitch), new PropertyMetadata(null));
		private Brush mBrushToggleOn;
		private Brush mBrushToggleOff;
		private Style mStyleToggle;
		private bool mBIsStyleFixed;
		internal ViewFlipper viewFliper;
		internal Grid TwoButtonViewPanel;
		internal TextBlock txtTitle;
		internal TextBlock txtToggle;
		internal ToggleSwitchButton toggleButton;
		private bool _contentLoaded;
		public string Text
		{
			get
			{
				return (string)base.GetValue(MMToggleSwitch.TextProperty);
			}
			set
			{
				base.SetValue(MMToggleSwitch.TextProperty, value);
				this.txtTitle.set_Text(value);
			}
		}
		public bool IsChecked
		{
			get
			{
				return (bool)base.GetValue(MMToggleSwitch.IsCheckedProperty);
			}
			set
			{
				base.SetValue(MMToggleSwitch.IsCheckedProperty, value);
				this.toggleButton.set_IsChecked(new bool?(value));
			}
		}
		public MMToggleSwitch()
		{
			this.InitializeComponent();
		}
		private void initData(object sender, RoutedEventArgs e)
		{
		}
		private void checkedOn(object sender, EventArgs e)
		{
			this.IsChecked = true;
			this.refreshShow();
			if (this.onToggleStateChanged != null)
			{
				this.onToggleStateChanged(this, true);
			}
		}
		private void checkedOff(object sender, EventArgs e)
		{
			this.IsChecked = false;
			this.refreshShow();
			if (this.onToggleStateChanged != null)
			{
				this.onToggleStateChanged(this, false);
			}
		}
		private void setStyles()
		{
			if (this.mBIsStyleFixed)
			{
				return;
			}
			this.mBrushToggleOn = R.theme.SETTING_ITEM_TITLE_BRUSH;
			this.mBrushToggleOff = R.theme.SETTING_DESC_WORD_BRUSH;
			this.mStyleToggle = R.theme.ToggleSwitchStyle;
		}
		public void FixStyleCool()
		{
			this.mBIsStyleFixed = true;
			this.mBrushToggleOn = (SolidColorBrush)Application.get_Current().get_Resources().get_Item("cool__SETTING_ITEM_TITLE_BRUSH");
			this.mBrushToggleOff = (SolidColorBrush)Application.get_Current().get_Resources().get_Item("cool__SETTING_DESC_WORD_BRUSH");
			this.mStyleToggle = (Style)Application.get_Current().get_Resources().get_Item("cool__ToggleSwitchStyle");
		}
		public void refreshShow()
		{
			this.setStyles();
			if (this.IsChecked)
			{
				this.txtToggle.set_Text(strings.Set_Main_Toggle_open);
				this.txtToggle.set_Foreground(this.mBrushToggleOn);
			}
			else
			{
				this.txtToggle.set_Text(strings.Set_Main_Toggle_close);
				this.txtToggle.set_Foreground(this.mBrushToggleOff);
			}
			this.toggleButton.set_Style(this.mStyleToggle);
		}
		[DebuggerNonUserCode]
		public void InitializeComponent()
		{
			if (this._contentLoaded)
			{
				return;
			}
			this._contentLoaded = true;
			Application.LoadComponent(this, new Uri("/MicroMsg;component/Source/UI/Util/MMToggleSwitch.xaml", 2));
			this.viewFliper = (ViewFlipper)base.FindName("viewFliper");
			this.TwoButtonViewPanel = (Grid)base.FindName("TwoButtonViewPanel");
			this.txtTitle = (TextBlock)base.FindName("txtTitle");
			this.txtToggle = (TextBlock)base.FindName("txtToggle");
			this.toggleButton = (ToggleSwitchButton)base.FindName("toggleButton");
		}
	}
}
